<template>
  <a-popover
    v-model="visible"
    trigger="click"
    placement="bottomRight"
    overlayClassName="header-notice-wrapper"
    :autoAdjustOverflow="true"
    :arrowPointAtCenter="true"
    :overlayStyle="{ width: '400px', top: '50px' }"
  >
    <template slot="content">
      <a-spin :spinning="loadding">
        <a-tabs>
          <a-tab-pane key="1">
            <template #tab>
              <span>
                <span class="messageTag">
                  信息通知
                  <a-badge class="tagBadge" count="5" style="width: 10px">
                    <a href="#" class="head-example" />
                  </a-badge>
                </span>

              </span>
            </template>
            <div class="messageBor">
              <div v-for="item in infoList"  class="contentTag">
                <div class="titleTag" :class="item.start===0?'otherClass':''" @click="linkTitle(item)">
                  <span v-if="item.titleSon">【{{item.title}}：{{item.titleSon}}】</span>
                  <span v-else>【{{item.title}}】</span>
<!--                  <span style="margin-left: 10px">您被指定为<span>【车辆编号245】</span>负责人，请知悉</span>-->
                  <span style="margin-left: 10px">{{item.head}}</span>
                </div>
                <div style="text-align: right">2020-12-11</div>
              </div>
            </div>
            <a-button  class='btn-blue' style="float: right;margin: 5px 0">全部已读</a-button>
          </a-tab-pane>
          <a-tab-pane  key="2">
            <template #tab>
              <span>
                <span class="messageTag">
                  重大决策
                  <a-badge class="tagBadge" count="7" style="width: 10px">
                    <a href="#" class="head-example" />
                  </a-badge>
                </span>

              </span>
            </template>
            重大决策
          </a-tab-pane>
          <a-tab-pane  key="3">
            <template #tab>
              <span>
                <span class="messageTag">
                  范围变更
                  <a-badge class="tagBadge" count="7" style="width: 10px">
                    <a href="#" class="head-example" />
                  </a-badge>
                </span>

              </span>
            </template>
            范围变更
          </a-tab-pane>
          <a-tab-pane  key="4">
            <template #tab>
              <span>
                <span class="messageTag">
                  计划变更
                  <a-badge class="tagBadge" count="7" style="width: 10px">
                    <a href="#" class="head-example" />
                  </a-badge>
                </span>

              </span>
            </template>
            计划变更
          </a-tab-pane>

        </a-tabs>
      </a-spin>
    </template>
    <span @click="fetchNotice" class="header-notice">
      <a-badge count="12">
        <a-icon style="font-size: 16px; padding: 4px" type="bell" />
      </a-badge>
    </span>
  </a-popover>
</template>

<script>
  import socket from "../../../core/utils/socket";
export default {
  name: 'HeaderNotice',
  data () {
    return {
      socket: new socket(),
      loadding: false,
      visible: false,
      infoList:[
        {
          title:'重点问题',
          titleSon:'项目重点问题',
          start:0,
          head:'您被指定为【车辆编号245】负责人，请知悉',
        },
        {
          title:'造车',
          titleSon:'ADV',
          start:0,
          head:'您被指定为【车辆编号245】负责人，请知悉',
        },
        {
          title:'试验',
          titleSon:'整车道路试验',
          start:0,
          head:'您被指定为【高数耐久性试验（DS44） 123】负责人，请知悉',
        },
        {
          title:'造车',
          titleSon:'ADV',
          start:1,
          head:'您被指定为【车辆编号245】负责人，请知悉',
        },
        {
          title:'零件俱乐部',
          titleSon:'',
          start:1,
          head:'零件俱乐部定时任务获取失败',
        },
        {
          title:'造车',
          titleSon:'ADV',
          start:1,
          head:'您被指定为【车辆编号245】负责人，请知悉',
        },
      ]
    }
  },
  created() {
    this.initialize()
    this.$store.dispatch('globalScoket',this.socket)
    // 监听返回数据
    this.socket.on('message', this.onMessage)
    this.socket.on('error', this.initialize)
  },
  // 离开页面 断开连接
  destroyed() {
    this.socket.destroy()
    console.log('断开连接')
  },
  methods: {
    linkTitle(item){
      console.log(item,'item')
      this.$router.push({ name: item.title,
        query:{
          mode: item.titleSon,
          }
      });
      this.fetchNotice()
    },
    initialize(){
      // 开启连接
      this.socket.doOpen();
      // 发送数据
      this.socket.on('open', () => {
        const data = {
          type:'1',
        };
        this.socket.send(data);
      });
    },
    //  接收返回的数据
    onMessage(data){
      console.log(data,'导航栏接收')
    },
    fetchNotice () {
      console.log('调下接口')
      // if (!this.visible) {
      //   this.loadding = true
      //   setTimeout(() => {
      //     this.loadding = false
      //   }, 100)
      // } else {
      //   this.loadding = false
      // }
      this.visible = !this.visible
    }
  }
}
</script>

<style lang="css">
  .header-notice-wrapper {
    top: 50px !important;
  }
</style>
<style lang="less" scoped>
  .header-notice{
    display: inline-block;
    transition: all 0.3s;

    span {
      vertical-align: initial;
    }
  }
  .messageTag{
    position: relative;
    .tagBadge{
      position: absolute;
    }
  }
  .messageBor{
    max-height: 350px;
    padding: 0 10px;
    height: 415px;
    overflow: auto;
    .contentTag{
      margin: 10px 0;
      .titleTag{
        cursor: pointer;
        font-weight:500;
        text-indent:8px;
        overflow: hidden;
        display: -webkit-box;               // 将对象作为弹性伸缩盒子模型显示 。
        text-overflow: ellipsis;            // 可以用来多行文本的情况下，用省略号“...”隐藏超出范围的文本 。
        -webkit-box-orient: vertical;       // 设置或检索伸缩盒对象的子元素的排列方式 。
        -webkit-line-clamp: 2;              // 限制在一个块元素显示的文本的行数。
      }
      .otherClass{
        color: #4E80EF;
        font-weight:600;
        font-size:15px;
      }
    }

  }
  .messageBor::-webkit-scrollbar{
    width:4px;
    height:4px;
    /**/
  }
  .messageBor::-webkit-scrollbar-track{
    background: rgb(239, 239, 239);
    border-radius:2px;
  }
  .messageBor::-webkit-scrollbar-thumb{
    background: #bfbfbf;
    border-radius:10px;
  }
  .messageBor::-webkit-scrollbar-thumb:hover{
    background: #333;
  }
  .messageBor::-webkit-scrollbar-corner{
    background: #179a16;
  }
</style>
